package com.tsing.basic.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsing.basic.service.IPermissionService;
import com.tsing.basic.vo.req.*;
import com.tsing.basic.vo.resp.PermissionRespVo;
import com.tsing.common.annotations.SystemLog;
import com.tsing.common.utils.ResultUtil;
import com.tsing.common.vo.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
@Api(tags = "权限管理")
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @PostMapping("/addPermission")
    @ApiOperation(value = "新增权限")
    @SystemLog(description = "新增权限")
    public ResultData addPermission(@Validated @RequestBody PermissionAddReqVo reqVo) {
        permissionService.addPermission(reqVo);
        return ResultUtil.success();
    }

    @DeleteMapping("/deletePermission")
    @ApiOperation(value = "删除权限")
    @SystemLog(description = "删除权限")
    public ResultData deletePermission(@Validated @RequestBody IdsReqVo reqVo) {
        permissionService.deletePermission(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/getPermission")
    @ApiOperation(value = "获取单个权限信息")
    @SystemLog(description = "获取单个权限信息")
    public ResultData<PermissionRespVo> getPermissionById(@Validated IdReqVo reqVo) {
        return ResultUtil.success(permissionService.getPermissionById(reqVo));
    }

    @PutMapping("/updatePermission")
    @ApiOperation(value = "修改权限信息")
    @SystemLog(description = "修改权限信息")
    public ResultData updatePermission(@Validated @RequestBody PermissionUpdateReqVo reqVo) {
        permissionService.updatePermission(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/permissionPage")
    @ApiOperation(value = "权限分页")
    @SystemLog(description = "权限分页")
    public ResultData<Page<PermissionRespVo>> permissionPage(@Validated PermissionPageReqVo reqVo) {
        return ResultUtil.success(permissionService.permissionPage(reqVo));
    }

}
